import { Injectable } from '@nestjs/common';
import { SysDict } from './entities/sys_dict.entity';
import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { SysDictKey } from '../shared/enum';

@Injectable()
export class SysDictService {
  constructor(
    @InjectRepository(SysDict)
    private sysDict: Repository<SysDict>,
  ) {}

  async getSysDictValue(key: SysDictKey) {
    const { value } = await this.sysDict.findOne({
      where: {
        key,
      },
    });
    if (!value) throw new Error('获取失败');
    return { result: JSON.parse(value) };
  }
}
